<template>
  <common-layout>
    <div class="top">
      <div class="header">
        <img alt="logo" class="logo" src="@/assets/img/logo.png" />
        <span class="title">忘记密码</span>
      </div>
    </div>
    <div class="login">
      <a-form
        :form="form"
        :label-col="{ span: 8 }"
        :wrapper-col="{ span: 12 }"
        @submit="handleSubmit"
      >
        <a-form-item label="手机号">
          <a-input
            v-decorator="[
              'mobile',
              { rules: [{ required: true, message: '请输入手机号！' }] },
            ]"
          />
        </a-form-item>
        <a-form-item label="新密码">
          <a-input
            v-decorator="[
              'confirmPsw',
              { rules: [{ required: true }] },
            ]"
          />
        </a-form-item>
        <a-form-item label="确认新密码">
          <a-input
            v-decorator="[
              'password',
              { rules: [{ required: true, validator: this.confirmPsw }] },
            ]"
          />
        </a-form-item>

        <a-form-item :wrapper-col="{ span: 12, offset: 8}">
          <a-row :gutter="6">
            <a-col :span="12">
              <a-button type="primary" html-type="submit"> 提交 </a-button>
            </a-col>
            <a-col :span="12">
              <a-button @click="handleBack" type="danger">
                返回
              </a-button></a-col
            >
          </a-row>
        </a-form-item>
      </a-form>
    </div>
  </common-layout>
</template>

<script>
// 账号15961858835
// 密码 123456
// 账号18362375700
// 密码 234567

import CommonLayout from "@/layouts/CommonLayout";
import { forgetPass } from "../../services/dataSource";
import { setAuthorization } from "@/utils/request";
// import { loadRoutes } from "@/utils/routerUtil";
import { mapMutations } from "vuex";

export default {
  name: "Login",
  components: { CommonLayout },
  data() {
    return {
      // logging: false,
      error: "",
      form: this.$form.createForm(this),
    };
  },
  computed: {},
  methods: {
    handleBack() {
      this.$router.push("/login");
    },
    handleSubmit(e) {
      e.preventDefault();
      this.form.validateFields((err, values) => {
        if (!err) {
          const { mobile, password } = values;
          forgetPass(mobile, password).then((res) => {
            if (res.data.success) {
              this.$message.success("密码重置成功,即将返回登录页！");
              setTimeout(() => {
                this.handleBack();
              }, 3000);
            } else {
              this.$message.error("重置密码错误，请联系管理员");
            }
          });
        }
      });
    },
    confirmPsw(rule,value,callback){
      if (value) {
            var datas = this.form.getFieldsValue();
            if (value != datas.confirmPsw) {
                callback('两次密码输入不一致');
            } else {
                callback();
            }
        }
        callback();
    }
  },
  created() {},
};
</script>

<style lang="less" scoped>
.common-layout {
  .top {
    text-align: center;
    margin-top: 8.125rem;
    .header {
      height: 44px;
      line-height: 44px;
      a {
        text-decoration: none;
      }
      .logo {
        height: 44px;
        vertical-align: top;
        margin-right: 16px;
      }
      .title {
        font-size: 33px;
        color: @title-color;
        font-family: "Myriad Pro", "Helvetica Neue", Arial, Helvetica,
          sans-serif;
        font-weight: 600;
        position: relative;
        top: 2px;
      }
    }
    .desc {
      font-size: 14px;
      color: @text-color-second;
      margin-top: 12px;
      margin-bottom: 40px;
    }
  }
  .login {
    width: 368px;
    margin: 20px auto;
    @media screen and (max-width: 576px) {
      width: 95%;
    }
    @media screen and (max-width: 320px) {
      .captcha-button {
        font-size: 14px;
      }
    }
    .icon {
      font-size: 24px;
      color: @text-color-second;
      margin-left: 16px;
      vertical-align: middle;
      cursor: pointer;
      transition: color 0.3s;

      &:hover {
        color: @primary-color;
      }
    }
  }
}
.ant-input {
  padding-left: 40px;
}
</style>
